package com.cdh.edu.controller.admin;


import com.cdh.edu.entity.subject.OneSubject;
import com.cdh.edu.service.SubjectService;
import com.cdh.utils.result.Restful;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author cdh
 * @since 2020-10-19
 */
@ApiModel(description = "课程分类管理")
@RestController
@RequestMapping("subject")
@CrossOrigin
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    // 添加技术分类
    // 获取上传的文件，把文件内容读取出来
    @ApiOperation(value = "读取Excel")
    @PostMapping("addSubject")
    public Restful addSubject(MultipartFile file){
        //上传过来的Excel文件
        subjectService.saveSubject(file,subjectService);
        return Restful.ok();
    }

    //技术分类列表(树形)
    @GetMapping("getAllSubject")
    public Restful getAllSubject(){
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return Restful.ok().data("list",list);
    }
}

